package com.cddx.logistics.controller;

import com.cddx.logistics.domain.dto.InsuranceQueryDTO;
import com.cddx.logistics.domain.pojo.Insurance;
import com.cddx.logistics.domain.vo.InsuranceVO;
import com.cddx.logistics.service.InsuranceService;
import com.cddx.logistics.util.model.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/insurance")
@Api(tags = "车辆保险管理")
public class InsuranceController {
    @Resource
    private InsuranceService insuranceService;

    @GetMapping("/queryPage")
    @ApiOperation("分页查询保险信息")
    public R queryPage(InsuranceQueryDTO queryDTO) {
        PageInfo<InsuranceVO> pageInfo = insuranceService.queryPage(queryDTO);
        return R.ok(pageInfo);
    }

    @PostMapping("/add")
    @ApiOperation("添加保险信息")
    public R add(Insurance insurance) {
        return insuranceService.add(insurance) ? R.ok("添加成功") : R.error("添加失败");
    }

    @PostMapping("/update")
    @ApiOperation("修改保险信息")
    public R update(Insurance insurance) {
        return insuranceService.update(insurance) ? R.ok("修改成功") : R.error("修改失败");
    }

    @GetMapping("/delete")
    @ApiOperation("删除保险信息")
    public R delete(Integer id) {
        return insuranceService.delete(id) ? R.ok("删除成功") : R.error("删除失败");
    }

    @PostMapping("/batchDelete")
    @ApiOperation("批量删除保险信息")
    public R batchDelete(@RequestBody List<Integer> ids) {
        return insuranceService.batchDelete(ids) ? R.ok("批量删除成功") : R.error("批量删除失败");
    }
}